#ifndef SCRIPTENVIRONMENTEX_H
#define SCRIPTENVIRONMENTEX_H

#include <defs/global.h>
#include <core/entityobject.h>
#include <scripting/scriptenvironment.h>
#include <QtScript>

typedef QScriptEngine::FunctionSignature ScriptFunction;

namespace Optra{ namespace Extensions {
        class ZoneInterface;
}}

O_PRIVATE_DECLARE(ScriptEnvironmentEx);
class ScriptEnvironmentEx : public Opl::Scripting::ScriptEnvironment
{
    Q_OBJECT
public:

    ScriptEnvironmentEx(ScriptEnvironmentMode mode, Opl::Core::EntityObject *parent = 0);
    ~ScriptEnvironmentEx();
    void initialize();

    const QString& errorString()const;
    void registerFunction(const QString& name, ScriptFunction function, const QString& package = "", QObject* data = 0);
    void registerObject(const QString& name, Opl::Core::EntityObject* object, const QString& package = "");

    void print(const QString& out);
    void printl(const QString& out);

signals:
//    void output(const QString& str);
//    void error(const QScriptValue & exception);

public slots:
    bool exec(const QString& script, bool debug);
    bool exec(const QString& script, const QString& filename = QString(), bool debug = false);
    void signalHandlerException(const QScriptValue & exception);

private slots:
    void errorHandler(const QScriptValue & exception);
private:
    O_PRIVATE_DECLARE_MEMBER(ScriptEnvironmentEx)
};

#endif // SCRIPTENVIRONMENTEX_H
